
var ModalBoxClass = new Class({
	
	initialize: function(loader) {
	
		this.create();
		this.setWidth();
		this.Loader = loader;
		
		new Drag(this.Box, {
			handle: this.BoxHead
		});
		
		this.BoxFx = new Fx.Tween(this.Box, {duration: 100});
		this.BoxClose.addEvent('click', this.close.create({bind: this}));
	},
	
	create: function () {
		
		this.Box = new Element('div', {
			'class': 'modalBox',
			'opacity': 0
		});
		
		this.BoxHead = new Element('div', {
			'class': 'modalHead'
		});
		
		this.BoxTitle = new Element('span', {
			'class': 'modalTitle'
		});
		
		this.BoxClose = new Element('span', {
			'class': 'modalClose'
		});
		
		this.BoxContener = new Element('div', {
			'class': 'modalContener'
		});
		
		this.Box.adopt([this.BoxHead, this.BoxContener]);
		this.BoxHead.adopt([this.BoxTitle, this.BoxClose]);
		
		this.Box.inject(document.body);
	},
	
	setWidth: function (width) {
		
		if (!width) width = 500;
		
		var wind = window.getSize();
		
		this.Box.setStyles({
			width: width,
			left: wind.x/2 - width/2,
			top: wind.y/2 - 200
		});
		
	},
	
	ajax: function (Url) {
		
		var Loader = $(this.Loader);
		
		this.BoxContener.set('load', {
	        evalScripts: true,
	        onRequest: function() {Loader.removeClass('hide');},
	        onSuccess: function(txt){Loader.addClass('hide');}
	    });
		this.BoxContener.load(Url);
	},
	
	setText: function (text) {
		
		this.BoxContener.set('html', text);		
	},
	
	setTitle: function (title) {
		
		this.BoxTitle.set('html', title);	
	},
	
	open: function() {
		
		this.BoxFx.start('opacity', 1);
	},
	
	close: function() {
		
		this.BoxFx.start('opacity', 0);
		this.setText('');
	},
	
	alert: function (Url, title) {
		
		this.setTitle(title);
		this.ajax(Url);
		this.open();
	},
	
	alertText: function (text, title) {
	
		this.setTitle(title);
		this.setText(text);
		this.open();
	}
});